/**
Custom module for you to write your own javascript functions
**/
var Custom = function () {

    // CLEARABLE INPUT
    function tog(v) {
        return v ? 'addClass' : 'removeClass';
    }

    // private functions & variables

    var serializeObject = function () {
        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    }

    var globalSearchEnterButtonFuncationality = function () {
        $(".txtGlobalSearch").keyup(function (event) {
            if (event.keyCode == 13) {
                $(".btnGlobalSearch").click();
            }
        });
    }

    var clearSeacrhTxtBox = function () {
        $(document).on('input', '.clearable', function () {
            $(this)[tog(this.value)]('x');
        }).on('mousemove', '.x', function (e) {
            $(this)[tog(this.offsetWidth - 18 < e.clientX - this.getBoundingClientRect().left)]('onX');
        }).on('touchstart click', '.onX', function (ev) {
            ev.preventDefault();
            $(this).removeClass('x onX').val('').change();
        });
        // $('.clearable').trigger("input");
        // Uncomment the line above if you pre-fill values from LS or server
    }

    // public functions
    return {

        //main function
        init: function () {
            //initialize here something.
            serializeObject();
            globalSearchEnterButtonFuncationality();
            clearSeacrhTxtBox();
        },

        //some helper function
        serializeObject: function () {
            
        }

    };

}();

/***
Usage
***/
//Custom.init();
//Custom.doSomeStuff();